<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title data-i18n="resources.title_routeLocatorPoint"></title>
  <script type="text/javascript" src="../js/include-web.js"></script>
  <script type="text/javascript" src="../../dist/maplibregl/include-maplibregl.js"></script>
  <style>
    .maplibregl-popup-close-button {
      outline: none;
    }
  </style>
</head>

<body style="margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  <script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map,
      routeLocatorParameters_point, routeLocatorService,
      attribution = "<a href='https://maplibre.org/' target='_blank'>© MapLibre </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
        " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ",
      mapUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}",
      serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";

    map = new maplibregl.Map({
      container: 'map',
      style: {
        "version": 8,
        "sources": {
          "raster-tiles": {
            "attribution": attribution,
            "type": "raster",
            "tiles": [mapUrl],
            "tileSize": 256
          }
        },
        "layers": [{
          "id": "simple-tiles",
          "type": "raster",
          "source": "raster-tiles",
        }]
      },
      center: [116.2740019864, 39.8970124079],
      zoom: 12
    });
    map.addControl(new maplibregl.NavigationControl(), 'top-left');
    map.addControl(new maplibregl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');

    map.on("load", function () {
      routeCalculateMeasureProcess();
    });

    function routeCalculateMeasureProcess() {

      var piontLists = [
        [116.2143386597, 39.8959419733, 0],
        [116.217501999125, 39.896670999665, 282.3879789906],
        [116.220156000875, 39.896820999605, 511.787745072744],
        [116.228716999, 39.8968419995966, 1253.201708792909],
        [116.25000000025, 39.8968619995886, 3103.167523778722],
        [116.27412300025, 39.8967689996258, 5201.062444476062],
        [116.310443000875, 39.8971139994878, 8360.617856315024],
        [116.344168500812, 39.8976724992644, 11294.738396325054]
      ];

      var LineGeometryData = {
        "type": "Feature",
        "geometry": {
          "type": "LineString",
          "coordinates": piontLists
        }
      };
      map.addLayer({
        "id": "route",
        "type": "line",
        "source": {
          "type": "geojson",
          "data": LineGeometryData
        },
        "layout": {
          "line-join": "round",
          "line-cap": "round"
        },
        "paint": {
          "line-color": "#888",
          "line-width": 8
        }
      });

      //将形成路由的点提出来，为了构造下面点定里程服务sourceRoute
      var routeLine = LineGeometryData;

      //点定里程服务
      routeLocatorService = new maplibregl.supermap.SpatialAnalystService(serviceUrl);
      routeLocatorParameters_point = new maplibregl.supermap.RouteLocatorParameters({
        "sourceRoute": routeLine,
        "type": "POINT",
        "measure": 6753,
        "offset": 0,
        "isIgnoreGap": true
      });
      routeLocatorService.routeLocate(routeLocatorParameters_point).then(function (routeLocateServiceResult) {
        var point = routeLocateServiceResult.result.resultGeometry.geometry.coordinates;
        map.addLayer({
          "id": "Point",
          "type": "circle",
          "source": {
            "type": "geojson",
            "data": {
              "type": "Feature",
              "geometry": {
                "type": "Point",
                "coordinates": point
              }
            }
          },
          "paint": {
            "circle-radius": 6,
            "circle-color": "red",
          },
        });
        var innerHTML = resources.msg_queryMileagePoint1 + routeLocatorParameters_point.measure + resources.msg_queryMileagePoint2;
        new maplibregl.Popup().setLngLat(point).setHTML(innerHTML).addTo(map);
      });
    }
  </script>

</body>

</html>
